import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import path from 'path'
import styleImport from 'vite-plugin-style-import'
import tsconfigPaths from 'vite-tsconfig-paths'
const resolve = (dir: string) => path.join(__dirname, dir)

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    tsconfigPaths(),
    // styleImport({
    //   libs: [
    //     {
    //       libraryName: 'element-plus',
    //       esModule: true,
    //       ensureStyleFile: true,
    //       resolveStyle: name => {
    //         name = name.slice(3)
    //         return `element-plus/packages/theme-chalk/src/${name}.scss`
    //       },
    //       resolveComponent: name => {
    //         return `element-plus/lib/${name}`
    //       },
    //     },
    //   ],
    // }),
  ],
  base: './', // 打包路径
  resolve: {
    extensions: ['.js', '.ts', '.jsx', '.tsx'],
    alias: {
      '@': resolve('./src'), // 设置别名
      apis: resolve('./src/apis'),
      hooks: resolve('./src/hooks'),
      components: resolve('./src/components'),
      views: resolve('./src/views'),
      styles: resolve('./src/styles'),
      utils: resolve('./src/utils'),
    },
  },
  server: {
    port: 8099, // 启动端口
    open: false,
    proxy: {
      // 选项写法
      '/api': {
        target: 'http://192.168.0.125:8904', // 代理网址
        changeOrigin: true,
        rewrite: path => path.replace(/^\/api/, ''),
      },
    },
    cors: true,
  },
  // CSS预处理器
  css: {
    preprocessorOptions: {
      scss: {
        additionalData: `
          @import "./src/styles/variables.scss";
          @import "./src/styles/mixin.scss";
        `,
      },
    },
  },
})
